﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

namespace CRM.Web.Common
{
    public class WebCommon
    {
        public static string GetPageResourcesPath()
        {
            string path = string.Empty;
            if (ConfigurationManager.AppSettings["ResourcesPath"] != null)
            {
                path = ConfigurationManager.AppSettings["ResourcesPath"].ToString();
            }
            if (String.IsNullOrEmpty(path))
            {
                int layer = 1;
                if (HttpContext.Current.Request.ApplicationPath.ToLower() == "/")
                {
                    layer = HttpContext.Current.Request.Path.ToLower().TrimStart('/').Split('/').Length;
                }
                else
                {
                    layer = HttpContext.Current.Request.Path.ToLower().Replace(HttpContext.Current.Request.ApplicationPath.ToLower(), "").TrimStart('/').Split('/').Length;
                }
                for (int i = layer; i > 0; i--)
                {
                    if (i == 1)
                    {
                        path += "Resources/";
                    }
                    else
                    {
                        path += "../";
                    }
                }

            }
            return path;
        }
    }
}
